--[[ 编码: WMS-82-01 名称: 批量入库测试-创建后 作者:HAN 日期:2025-1-29 级别:固定 (说明本段代码在项目中不太会变化) 函数: AfterDataObjCreate 功能: 更改记录: --]] wms_wh = require( "wms_wh" ) local function set_error_info( strLuaDEID, id, strErr ) local nRet, strRetInfo local strSetSQL = "S_ERR = '"..strErr.."'" strCondition = "S_ID = '"..id.."'" nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "TEST_Inbound", strCondition, strSetSQL) if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "设置【上架策略测试】信息失败!"..strRetInfo) end end function AfterDataObjCreate ( strLuaDEID ) -- step1: 获取当前【上架策略测试】对象 local test nRet, test = m3.GetSysCurEditDataObj( strLuaDEID, "TEST_Inbound" ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..test ) end if ( test.cntr_code == '' or test.cntr_code == nil ) then lua.Error( strLuaDEID, debug.getinfo(1), "容器号不能为空! " ) end -- 仓库编码库区编码2个必须一个有值 if ( test.wh_code == '' and test.area_code == '') then set_error_info( strLuaDEID, test.id, "仓库编码,库区编码两个必须一个有值!" ) return end lua.Debug( strLuaDEID, debug.getinfo(1), "test", test ) -- step2:判断容器是否存在,如果存在就设置错误信息,不继续进行测试 if ( wms_cntr.Exist( strLuaDEID, test.cntr_code ) == false ) then -- 【容器】不存在要先创建【容器】 local container = m3.AllocObject(strLuaDEID,"Container") container.code = test.cntr_code nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, container) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), '创建【容器】对象失败!'..strRetInfo ) end else set_error_info( strLuaDEID, test.id, "容器号:'"..test.cntr_code.."'已经存在!" ) return end -- step3 创建【容器货品明细】 local cg_detail = m3.AllocObject(strLuaDEID,"CG_Detail") cg_detail.cntr_code = test.cntr_code cg_detail.serial_no = test.serial_no cg_detail.batch_no = test.batch_no cg_detail.item_code = test.item_code cg_detail.item_name = test.item_name cg_detail.qty = test.qty cg_detail.uom = "pc" nRet, cg_detail = m3.CreateDataObj( strLuaDEID, cg_detail ) if ( nRet ~= 0 ) then lua.Debug( strLuaDEID, debug.getinfo(1), "创建 cg_detail 失败", cg_detail ) set_error_info( strLuaDEID, test.id, "创建 cg_detail 失败!见调试日志" ) return end -- step4 如果导入的时候 排列层 有值直接入库 local ret_loc = {} if ( test.row ~= nil and test.col ~= nil and test.layer ~= nil and test.area_code ~= '') then local loc_code = wms_wh.GetLocCodeByRCL( strLuaDEID, test.area_code, test.row, test.col, test.layer ) if ( loc_code == '' ) then set_error_info( strLuaDEID, test.id,"根据排列层信息无法获取货位编码!" ) return end -- 直接入库 ret_loc.loc_code = loc_code else -- step4 通过上架策略计算可上架的货位 local item_info = {} item_info.cntr_code = test.cntr_code item_info.item_code = test.item_code item_info.item_name = test.item_name item_info.batch_no = test.batch_no if ( test.area_code ~= '' and test.area_code ~= nil ) then nRet, strRetInfo = wms.wms_GetAreaAvaliableLocByRule( strLuaDEID, test.area_code, test.put_away, lua.table2str(item_info) ) else nRet, strRetInfo = wms.wms_GetWHAvaliableLocByRule( strLuaDEID, test.wh_code, test.put_away, lua.table2str(item_info) ) end if ( nRet ~= 0 ) then lua.Debug( strLuaDEID, debug.getinfo(1), "根据上架策略计算可上架货位失败!", strRetInfo ) set_error_info( strLuaDEID, test.id, "根据上架策略计算可上架货位失败!见调试日志" ) return end if ( strRetInfo == '') then set_error_info( strLuaDEID, test.id, "根据上架策略没有符合条件的货位!" ) return end local success success, ret_loc = pcall( json.decode, strRetInfo) if ( success == false or ret_loc.loc_code == nil or ret_loc.loc_code == '') then lua.Debug( strLuaDEID, debug.getinfo(1), "上架策略返回json不合法!", strRetInfo ) set_error_info( strLuaDEID, test.id, "上架策略返回json不合法! 见调试日志" ) return end lua.Debug( strLuaDEID, debug.getinfo(1), "系统分配的货位", ret_loc ) end -- 不生产作业进行模拟,直接入库 local loc nRet, loc = wms_wh.GetLocInfo( ret_loc.loc_code ) if ( nRet ~= 0 ) then lua.Debug( strLuaDEID, debug.getinfo(1), "WMS_GetLocInfo失败!", loc ) set_error_info( strLuaDEID, test.id, "WMS_GetLocInfo失败!" ) return end lua.Debug( strLuaDEID, debug.getinfo(1), "loc", loc ) nRet, strRetInfo = wms_wh.Loc_Container_Binding( strLuaDEID, loc.code, test.cntr_code, "绑定解绑方法-系统", "测试" ) if ( nRet ~= 0 ) then lua.Debug( strLuaDEID, debug.getinfo(1), "货位容器绑定错误!", strRetInfo ) set_error_info( strLuaDEID, test.id, "货位容器绑定错误! 见调试日志" ) return end -- 加库区/库量表 (通过CG_Detail) nRet, strRetInfo = wms_base.Add_WHAreaQty_ByCGDetail(strLuaDEID, loc.wh_code, loc.area_code, test.cntr_code ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), strRetInfo ) end local strSetSQL = "S_LOC_CODE = '"..loc.code.."', N_ROW = "..loc.row..", N_COL = "..loc.col..", N_LAYER = "..loc.layer strSetSQL = strSetSQL..", N_POS = "..loc.pos..", N_ROW_GROUP = "..loc.row_group..", N_AISLE = "..loc.aisle strCondition = "S_ID = '"..test.id.."'" nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "TEST_Inbound", strCondition, strSetSQL) if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "设置【上架策略测试】信息失败!"..strRetInfo) end end